<html>
<head><meta charset="utf-8"><title>autocompleting feature cfg · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html">autocompleting feature cfg</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244837228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244837228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244837228">(Jul 04 2021 at 03:05)</a>:</h4>
<p>Has there ever been anything done for autocompleting cfg? specifically, completing feature cfgs. I think it'd be quite useful and id be wiling to work on it myself. Perhaps just start with <code>feature</code> completions then in the future expand it to other things like target, target_arch, etc</p>



<a name="244851137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244851137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244851137">(Jul 04 2021 at 09:41)</a>:</h4>
<p>I think this is implemented, I havnen't checked if it actually works</p>



<a name="244851139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244851139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244851139">(Jul 04 2021 at 09:41)</a>:</h4>
<p>See the PR that added this field: <a href="https://github.com/matklad/rust-analyzer/blob/e9d52c23b3b4f458a778a75870faa87cac57aaee/crates/base_db/src/input.rs#L185">https://github.com/matklad/rust-analyzer/blob/e9d52c23b3b4f458a778a75870faa87cac57aaee/crates/base_db/src/input.rs#L185</a></p>



<a name="244868404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244868404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244868404">(Jul 04 2021 at 17:09)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> that seems different, there is no cfg macro handling of any kind, this kind of completion would prob need some manual parsing of the cfg predicates. If i were to implement this im confused on a couple of things:</p>
<ul>
<li>how do i get the current crate's available features? i found something in the package crate but i found no way to get the actual package</li>
<li>RA doesnt autocomplete strings, no? so how would i autocomplete in this case?</li>
</ul>



<a name="244868514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244868514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244868514">(Jul 04 2021 at 17:12)</a>:</h4>
<p>wait i am blind that field literally gives me all i need</p>



<a name="244868574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244868574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244868574">(Jul 04 2021 at 17:14)</a>:</h4>
<p>i see, so cfg can already parse cfg just fine, however, i dont think we can use that because to autocomplete this we would need to know the exact token that is being autocompleted using child_range (i think its called)</p>



<a name="244868780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244868780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244868780">(Jul 04 2021 at 17:20)</a>:</h4>
<p>yeah i see, the difference is that <code>cfg</code> is used for deactivating code if a cfg directive disables it, while what we actually need is error tolerant parsing of the cfg predicates. Ive done plenty of error tolerant parsing with rowan but parsing from existing tokens is... weird. Because we can't build a rowan node for this because there is no syntax kind that is appropriate for this AFAIK. So im not sure what approach to take, ideally we would build a tree, modify it in place, then write it back, so we dont need to write an entire cfg serializer</p>



<a name="244868935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244868935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244868935">(Jul 04 2021 at 17:24)</a>:</h4>
<p>maybe what we could do is unite the existing code and this code and the completion code and parse this into a proper ast node then just reuse that for both pieces of code? that way we dont duplicate code needlessly, we dont have two things to maintain, the code works on cfg with errors, and we get a nice rowan repr for it</p>



<a name="244870445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244870445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244870445">(Jul 04 2021 at 18:06)</a>:</h4>
<p>I think it just works already perhaps?</p>



<a name="244870447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244870447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244870447">(Jul 04 2021 at 18:06)</a>:</h4>
<p><a href="/user_uploads/4715/Zy1TY85nlCjdXrQZLcK0LSag/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/Zy1TY85nlCjdXrQZLcK0LSag/image.png" title="image.png"><img src="/user_uploads/4715/Zy1TY85nlCjdXrQZLcK0LSag/image.png"></a></div>



<a name="244870556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244870556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244870556">(Jul 04 2021 at 18:09)</a>:</h4>
<p>I guess it doesn't handle <code>cfg!()</code>, but that should be easy to add</p>



<a name="244870853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244870853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244870853">(Jul 04 2021 at 18:17)</a>:</h4>
<p>huh, it does not work for me <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="244874953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/autocompleting%20feature%20cfg/near/244874953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/autocompleting.20feature.20cfg.html#244874953">(Jul 04 2021 at 20:00)</a>:</h4>
<p>I had to explicitly request completion with ctrl+space. Might make sense to check versions of things and logs?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>